﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.Revit;
using YArchitech.Revit.RevitExtension;
using YJKArch.Utils;
using YJKControls.Previewer;
using HYRevitCode.RevitDimensionUtility;

namespace YJKArch.AxisModule
{
	public partial class RectAxisForm : System.Windows.Forms.Form
	{
		[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, ExactSpelling = true, SetLastError = true)]
		internal static extern void MoveWindow(IntPtr hwnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);

		public RectAxisForm()
		{
			this.InitializeComponent();
			this.m_dataFromDlg = new RectAxisDataFromDlg();
		}

		public RectAxisForm(ExternalCommandData cmdData)
		{
			this.InitializeComponent();
			this.pictureBox3 = new Previewer(1u);
			this.pictureBox3.Paint += this.pictureBox3_Paint;
			base.Controls.Add(this.pictureBox3);
			this.pictureBox3.BackColor = System.Drawing.Color.White;
			this.pictureBox3.BorderStyle = BorderStyle.FixedSingle;
			this.pictureBox3.Location = this.panelPeview.Location;
			this.pictureBox3.Name = "pictureBox3";
			this.pictureBox3.Size = this.panelPeview.Size;
			this.pictureBox3.SizeMode = PictureBoxSizeMode.AutoSize;
			this.pictureBox3.BackColor = System.Drawing.Color.White;
			this.pictureBox3.TabIndex = 55;
			this.pictureBox3.TabStop = false;
			this.revit = cmdData;
			this.m_docment = cmdData.Application.ActiveUIDocument.Document;
			this.m_bExpand = false;
			this.m_dataFromDlg = new RectAxisDataFromDlg();
			this.Number = new DataGridViewTextBoxColumn();
			this.Number.HeaderText = "数目";
			this.Number.DataPropertyName = "Number";
			this.Number.Width = 52;
			this.Dist = new DataGridViewTextBoxColumn();
			this.Dist.HeaderText = "距离";
			this.Dist.DataPropertyName = "Dist";
			this.Dist.Width = 63;
			this.gridView.Columns.AddRange(new DataGridViewColumn[]
			{
				this.Number,
				this.Dist
			});
			this.bindingSourceLeft.DataSource = typeof(AxisListItem);
			this.bindingSourceRight.DataSource = typeof(AxisListItem);
			this.bindingSourceTop.DataSource = typeof(AxisListItem);
			this.bindingSourceDown.DataSource = typeof(AxisListItem);
			this.gridView.AutoGenerateColumns = false;
			this.radioLeft.Checked = true;
			this.gridView.DataSource = this.bindingSourceLeft;
			this.bindingSourceLeft.DataSource = this.m_dataFromDlg.LeftData;
			this.bindingSourceRight.DataSource = this.m_dataFromDlg.RightData;
			this.bindingSourceTop.DataSource = this.m_dataFromDlg.TopData;
			this.bindingSourceDown.DataSource = this.m_dataFromDlg.DownData;
			this.InitCmbGridType();
			this.InitCmbDimType();
			this.InitCmbAxisStyle();
			if (this.ReadAxisData())
			{
				this.RefreshControls();
				this.IsChange = true;
				this.pictureBox3.Refresh();
			}
		}

		private void listDist_MouseClick(object sender, MouseEventArgs e)
		{
			if (this.listDist.SelectedItem != null && ((ListBox)sender).IndexFromPoint(e.X, e.Y) != -1)
			{
				double dist = Convert.ToDouble(this.listDist.SelectedItem);
				if (this.radioLeft.Checked)
				{
					this.AddRow(this.m_dataFromDlg.LeftData, this.bindingSourceLeft, dist);
				}
				else if (this.radioRight.Checked)
				{
					this.AddRow(this.m_dataFromDlg.RightData, this.bindingSourceRight, dist);
				}
				else if (this.radioUp.Checked)
				{
					this.AddRow(this.m_dataFromDlg.TopData, this.bindingSourceTop, dist);
				}
				else if (this.radioDown.Checked)
				{
					this.AddRow(this.m_dataFromDlg.DownData, this.bindingSourceDown, dist);
				}
				this.IsChange = true;
				this.RefreshControls();
				this.pictureBox3.Refresh();
			}
		}

		private void AddRow(List<AxisListItem> data, BindingSource bSource, double dist)
		{
			if (data.Count < 1)
			{
				bSource.Add(new AxisListItem(1, dist));
				return;
			}
			if (Geometry.IsEqual(data[data.Count - 1].Dist, 0.0))
			{
				int number = data[data.Count - 1].Number;
				bSource.List[bSource.List.Count - 1] = new AxisListItem(number, dist);
				bSource.ResetBindings(false);
				return;
			}
			bSource.Add(new AxisListItem(1, dist));
		}

		private void AddRow1(List<AxisListItem> data, BindingSource bSource, double dist)
		{
			if (data.Count < 1)
			{
				bSource.Add(new AxisListItem(1, dist));
				return;
			}
			if (Geometry.IsEqual(data[data.Count - 1].Dist, 0.0))
			{
				int number = data[data.Count - 1].Number;
				bSource.List[bSource.List.Count - 1] = new AxisListItem(1, dist);
				bSource.ResetBindings(false);
				return;
			}
			bSource.Add(new AxisListItem(1, dist));
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.OK;
		}

		private bool DataIsCorrect()
		{
			string text = "ABCDEFGHJKLMNPQRSTUVWXY1234567890-_";
			if (this.m_dataFromDlg.LeftData.Count + this.m_dataFromDlg.RightData.Count < 1 || this.m_dataFromDlg.TopData.Count + this.m_dataFromDlg.DownData.Count < 1)
			{
				new DlgMessage("进深或开间数据不能为空，请检查！").ShowDialog();
				return false;
			}
			if (this.textBoxXStart.Text == "")
			{
				new DlgMessage("X向起始轴号为空，请检查！").ShowDialog();
				this.textBoxXStart.Focus();
				return false;
			}
			if (this.textBoxYStart.Text == "")
			{
				new DlgMessage("Y向起始轴号为空，请检查！").ShowDialog();
				this.textBoxYStart.Focus();
				return false;
			}
			for (int i = 0; i < this.textBoxXStart.Text.Length; i++)
			{
				if (!text.Contains(this.textBoxXStart.Text.Substring(i, 1)))
				{
					new DlgMessage("X向起始轴号含有非法字符，请检查！").ShowDialog();
					this.textBoxXStart.Focus();
					return false;
				}
			}
			for (int j = 0; j < this.textBoxYStart.Text.Length; j++)
			{
				if (!text.Contains(this.textBoxYStart.Text.Substring(j, 1)))
				{
					new DlgMessage("Y向起始轴号含有非法字符，请检查！").ShowDialog();
					this.textBoxYStart.Focus();
					return false;
				}
			}
			if (this.checkBoxDim.Checked && this.cmbDimType.SelectedItem == null)
			{
				new DlgMessage("请先选择一种线形标注样式！").ShowDialog();
				this.cmbDimType.Focus();
				return false;
			}
			return true;
		}

		private void radioLeft_CheckedChanged(object sender, EventArgs e)
		{
			this.FilterNullRow();
			this.gridView.DataSource = this.bindingSourceLeft;
			this.m_PreviousDataSourceType = RectAxisForm.DataSourceType.DST_LEFT;
		}

		private void radioRight_CheckedChanged(object sender, EventArgs e)
		{
			this.FilterNullRow();
			this.gridView.DataSource = this.bindingSourceRight;
			this.m_PreviousDataSourceType = RectAxisForm.DataSourceType.DST_RIGHT;
		}

		private void radioUp_CheckedChanged(object sender, EventArgs e)
		{
			this.FilterNullRow();
			this.gridView.DataSource = this.bindingSourceTop;
			this.m_PreviousDataSourceType = RectAxisForm.DataSourceType.DST_UP;
		}

		private void radioDown_CheckedChanged(object sender, EventArgs e)
		{
			this.FilterNullRow();
			this.gridView.DataSource = this.bindingSourceDown;
			this.m_PreviousDataSourceType = RectAxisForm.DataSourceType.DST_DOWN;
		}

		private void btnClean_Click(object sender, EventArgs e)
		{
			if (this.radioLeft.Checked)
			{
				this.bindingSourceLeft.Clear();
			}
			else if (this.radioRight.Checked)
			{
				this.bindingSourceRight.Clear();
			}
			else if (this.radioUp.Checked)
			{
				this.bindingSourceTop.Clear();
			}
			else if (this.radioDown.Checked)
			{
				this.bindingSourceDown.Clear();
			}
			this.RefreshControls();
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void btnLoad_Click(object sender, EventArgs e)
		{
			if (this.ReadAxisData())
			{
				this.RefreshControls();
				this.m_dataFromDlg.ExtendX = Convert.ToDouble(this.extendA.Text);
				this.m_dataFromDlg.ExtendY = Convert.ToDouble(this.extendB.Text);
				this.m_dataFromDlg.Angle = Convert.ToDouble(this.textBoxAngle.Text);
				this.IsChange = true;
				this.pictureBox3.Refresh();
			}
		}

		private void gridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
		{
			this.RefreshControls();
			this.pictureBox3.Refresh();
		}

		private void checkBoxDim_CheckedChanged(object sender, EventArgs e)
		{
			this.cmbDimType.Enabled = this.checkBoxDim.Checked;
			this.m_dataFromDlg.WithDim = this.checkBoxDim.Checked;
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void InitCmbGridType()
		{
			foreach (GridType gridType in Common.GetGridTypes(this.m_docment))
			{
				GridType gridType2 = gridType as GridType;
				if (gridType2.Name.IndexOf('_') < 0)
				{
					this.cmbGridType.Items.Add(gridType2.Name);
				}
			}
			if (this.cmbGridType.Items.Count > 0)
			{
				this.cmbGridType.SelectedIndex = 0;
			}
		}

		private DimensionType GetHYAxisDimType(List<BuiltInParameter> lstBldInPara)
		{
			DimensionType result = null;
			Transaction transaction = new Transaction(this.m_docment, "GetHYAxisDimType");
			try
			{
				transaction.Start();
				result = RevitDimensionUtiltyMethod.GetDimensionType(this.m_docment, DimensionTypeEnum.AxisDimension, lstBldInPara);
				transaction.Commit();
			}
			catch
			{
				transaction.RollBack();
			}
			return result;
		}

		private void InitCmbDimType()
		{
			DimensionType hyaxisDimType = this.GetHYAxisDimType(new List<BuiltInParameter>
			{
				BuiltInParameter.DIM_WITNS_LINE_EXTENSION_BELOW
			});
			if (hyaxisDimType != null)
			{
				ShowDimensionType item = new ShowDimensionType(hyaxisDimType);
				this.cmbDimType.Items.Add(item);
			}
			foreach (DimensionType dimensionType in Common.GetDimensionTypes(this.m_docment))
			{
				DimensionType dimensionType2 = dimensionType as DimensionType;
				if ((int)dimensionType2.StyleType == 0)
				{
					Parameter parameter = dimensionType2.get_Parameter(BuiltInParameter.DIM_WITNS_LINE_EXTENSION_BELOW);
					if (parameter != null && !parameter.IsReadOnly)
					{
						ShowDimensionType showDimensionType = new ShowDimensionType(dimensionType2);
						if (!this.cmbDimType.Items.Contains(showDimensionType) && !showDimensionType.Type.Name.Contains("@hy2"))
						{
							this.cmbDimType.Items.Add(showDimensionType);
						}
					}
				}
			}
			if (this.cmbDimType.Items.Count > 0)
			{
				this.cmbDimType.SelectedIndex = 0;
			}
		}

		private void InitCmbAxisStyle()
		{
			this.cmbXStyle.SelectedIndex = 1;
			this.cmbYStyle.SelectedIndex = 0;
		}

		private void RefreshControls()
		{
			double num = 0.0;
			double num2 = 0.0;
			for (int i = 0; i < this.m_dataFromDlg.LeftData.Count; i++)
			{
				num += this.m_dataFromDlg.LeftData.ElementAt(i).Dist * (double)this.m_dataFromDlg.LeftData.ElementAt(i).Number;
			}
			for (int j = 0; j < this.m_dataFromDlg.RightData.Count; j++)
			{
				num2 += this.m_dataFromDlg.RightData.ElementAt(j).Dist * (double)this.m_dataFromDlg.RightData.ElementAt(j).Number;
			}
			double value = (num > num2) ? num : num2;
			double num3 = 0.0;
			double num4 = 0.0;
			for (int k = 0; k < this.m_dataFromDlg.TopData.Count; k++)
			{
				num3 += this.m_dataFromDlg.TopData.ElementAt(k).Dist * (double)this.m_dataFromDlg.TopData.ElementAt(k).Number;
			}
			for (int l = 0; l < this.m_dataFromDlg.DownData.Count; l++)
			{
				num4 += this.m_dataFromDlg.DownData.ElementAt(l).Dist * (double)this.m_dataFromDlg.DownData.ElementAt(l).Number;
			}
			double value2 = (num3 > num4) ? num3 : num4;
			this.textBoxWidth.Text = Convert.ToString(value2);
			this.textBoxDepth.Text = Convert.ToString(value);
			this.cmbDimType.Enabled = this.checkBoxDim.Checked;
		}

		private void SaveAxisData()
		{
			FileStream fileStream = new FileStream(Product.UserDataLocation + "\\RectAxis.dat", FileMode.Create);
			StreamWriter streamWriter = new StreamWriter(fileStream);
			string text = Convert.ToString(this.m_dataFromDlg.Angle);
			streamWriter.WriteLine(text);
			text = "";
			for (int i = 0; i < this.bindingSourceLeft.Count; i++)
			{
				this.bindingSourceLeft.Position = i;
				AxisListItem axisListItem = this.bindingSourceLeft.Current as AxisListItem;
				text = string.Concat(new string[]
				{
					text,
					Convert.ToString(axisListItem.Number),
					"*",
					Convert.ToString(axisListItem.Dist),
					" "
				});
			}
			streamWriter.WriteLine(text);
			text = "";
			for (int j = 0; j < this.bindingSourceRight.Count; j++)
			{
				this.bindingSourceRight.Position = j;
				AxisListItem axisListItem = this.bindingSourceRight.Current as AxisListItem;
				text = string.Concat(new string[]
				{
					text,
					Convert.ToString(axisListItem.Number),
					"*",
					Convert.ToString(axisListItem.Dist),
					" "
				});
			}
			streamWriter.WriteLine(text);
			text = "";
			for (int k = 0; k < this.bindingSourceTop.Count; k++)
			{
				this.bindingSourceTop.Position = k;
				AxisListItem axisListItem = this.bindingSourceTop.Current as AxisListItem;
				text = string.Concat(new string[]
				{
					text,
					Convert.ToString(axisListItem.Number),
					"*",
					Convert.ToString(axisListItem.Dist),
					" "
				});
			}
			streamWriter.WriteLine(text);
			text = "";
			for (int l = 0; l < this.bindingSourceDown.Count; l++)
			{
				this.bindingSourceDown.Position = l;
				AxisListItem axisListItem = this.bindingSourceDown.Current as AxisListItem;
				text = string.Concat(new string[]
				{
					text,
					Convert.ToString(axisListItem.Number),
					"*",
					Convert.ToString(axisListItem.Dist),
					" "
				});
			}
			streamWriter.WriteLine(text);
			streamWriter.WriteLine(this.cmbGridType.SelectedIndex.ToString());
			streamWriter.WriteLine(this.checkBoxDim.Checked);
			streamWriter.WriteLine(this.cmbDimType.SelectedIndex.ToString());
			text = Convert.ToString(this.m_dataFromDlg.ExtendX);
			streamWriter.WriteLine(text);
			text = Convert.ToString(this.m_dataFromDlg.ExtendY);
			streamWriter.WriteLine(text);
			streamWriter.WriteLine(this.cbxUp.Checked);
			streamWriter.WriteLine(this.cbxDown.Checked);
			streamWriter.WriteLine(this.cbxLeft.Checked);
			streamWriter.WriteLine(this.cbxRight.Checked);
			streamWriter.Flush();
			streamWriter.Close();
			fileStream.Close();
		}

		private bool ReadDataByProjectSetting()
		{
			if (this.cmbGridType.Items.Count > 0)
			{
				this.cmbGridType.SelectedIndex = 0;
			}
			if (this.cmbDimType.Items.Count > 0)
			{
				this.cmbDimType.SelectedIndex = 0;
			}
			return true;
		}

		private bool ReadAxisData()
		{
			string path = Product.UserDataLocation + "\\RectAxis.dat";
			if (!File.Exists(path))
			{
				return this.ReadDataByProjectSetting();
			}
			FileStream fileStream = new FileStream(path, FileMode.Open);
			StreamReader streamReader = new StreamReader(fileStream);
			try
			{
				streamReader.BaseStream.Seek(0L, SeekOrigin.Begin);
				string text = streamReader.ReadLine();
				this.textBoxAngle.Text = text;
				text = streamReader.ReadLine();
				this.String2DistArray(text, ref this.bindingSourceLeft);
				text = streamReader.ReadLine();
				this.String2DistArray(text, ref this.bindingSourceRight);
				text = streamReader.ReadLine();
				this.String2DistArray(text, ref this.bindingSourceTop);
				text = streamReader.ReadLine();
				this.String2DistArray(text, ref this.bindingSourceDown);
				text = streamReader.ReadLine();
				this.cmbGridType.SelectedIndex = int.Parse(text);
				text = streamReader.ReadLine();
				this.checkBoxDim.Checked = Convert.ToBoolean(text);
				text = streamReader.ReadLine();
				this.cmbDimType.SelectedIndex = int.Parse(text);
				text = streamReader.ReadLine();
				this.extendA.Text = text;
				text = streamReader.ReadLine();
				this.extendB.Text = text;
				text = streamReader.ReadLine();
				this.cbxUp.Checked = Convert.ToBoolean(text);
				text = streamReader.ReadLine();
				this.cbxDown.Checked = Convert.ToBoolean(text);
				text = streamReader.ReadLine();
				this.cbxLeft.Checked = Convert.ToBoolean(text);
				text = streamReader.ReadLine();
				this.cbxRight.Checked = Convert.ToBoolean(text);
				streamReader.Close();
				fileStream.Close();
			}
			catch
			{
				streamReader.Close();
				fileStream.Close();
				File.Delete(path);
			}
			return true;
		}

		private void String2DistArray(string lineData, ref BindingSource bindingSource)
		{
			bindingSource.Clear();
			string[] array = lineData.Split(new char[]
			{
				' '
			});
			for (int i = 0; i < array.Length; i++)
			{
				string[] source = array[i].Split(new char[]
				{
					'*'
				});
				if (source.Count<string>() == 2)
				{
					AxisListItem axisListItem = new AxisListItem();
					axisListItem.Number = Convert.ToInt32(source.ElementAt(0));
					axisListItem.Dist = Convert.ToDouble(source.ElementAt(1));
					bindingSource.Add(axisListItem);
				}
			}
		}

		private void cmbXStyle_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.cmbXStyle.SelectedIndex == 0)
			{
				string largestAlpha = AxisNameManager.GetLargestAlpha(this.m_docment);
				this.textBoxXStart.Text = largestAlpha;
				this.cmbYStyle.SelectedIndex = 1;
				string text = AxisNameManager.GetLargestNumber(this.m_docment).ToString();
				this.textBoxYStart.Text = text;
				return;
			}
			if (this.cmbXStyle.SelectedIndex == 1)
			{
				string text2 = AxisNameManager.GetLargestNumber(this.m_docment).ToString();
				this.textBoxXStart.Text = text2;
				this.cmbYStyle.SelectedIndex = 0;
				string largestAlpha2 = AxisNameManager.GetLargestAlpha(this.m_docment);
				this.textBoxYStart.Text = largestAlpha2;
			}
		}

		private void cmbYStyle_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.cmbYStyle.SelectedIndex == 0)
			{
				string largestAlpha = AxisNameManager.GetLargestAlpha(this.m_docment);
				this.textBoxYStart.Text = largestAlpha;
				this.cmbXStyle.SelectedIndex = 1;
				string text = AxisNameManager.GetLargestNumber(this.m_docment).ToString();
				this.textBoxXStart.Text = text;
				return;
			}
			if (this.cmbYStyle.SelectedIndex == 1)
			{
				string text2 = AxisNameManager.GetLargestNumber(this.m_docment).ToString();
				this.textBoxYStart.Text = text2;
				this.cmbXStyle.SelectedIndex = 0;
				string largestAlpha2 = AxisNameManager.GetLargestAlpha(this.m_docment);
				this.textBoxXStart.Text = largestAlpha2;
			}
		}

		private void btnMoreParam_Click(object sender, EventArgs e)
		{
			this.m_bExpand = !this.m_bExpand;
			if (this.m_bExpand)
			{
				this.btnMoreParam.Text = "精简";
			}
			else
			{
				this.btnMoreParam.Text = "更多";
			}
			this.ShowHideMoreParam();
		}

		private void ShowHideMoreParam()
		{
			if (this.m_bExpand)
			{
				RectAxisForm.MoveWindow(base.Handle, base.Left, base.Top, base.Right - base.Left, base.Bottom - base.Top + 120, true);
				return;
			}
			RectAxisForm.MoveWindow(base.Handle, base.Left, base.Top, base.Right - base.Left, base.Bottom - base.Top - 120, true);
		}

		private void textBoxXStart_Leave(object sender, EventArgs e)
		{
			string text = this.textBoxXStart.Text;
			if (this.cmbXStyle.SelectedIndex == 0)
			{
				if (AxisNameManager.NumberIsAlreadyExisting(this.m_docment, text))
				{
					new DlgMessage("X向起始轴号已经存在，请重新输入").ShowDialog();
					this.textBoxXStart.Focus();
					this.textBoxXStart.SelectAll();
					return;
				}
			}
			else if (this.cmbXStyle.SelectedIndex == 1 && AxisNameManager.NumberIsAlreadyExisting(this.m_docment, text))
			{
				new DlgMessage("X向起始轴号已经存在，请重新输入").ShowDialog();
				this.textBoxXStart.Focus();
				this.textBoxXStart.SelectAll();
			}
		}

		private void textBoxYStart_Leave(object sender, EventArgs e)
		{
			string text = this.textBoxYStart.Text;
			if (this.cmbYStyle.SelectedIndex == 0)
			{
				AxisNameManager.GetLargestAlpha(this.m_docment);
				if (AxisNameManager.NumberIsAlreadyExisting(this.m_docment, text))
				{
					new DlgMessage("Y向起始轴号已经存在，请重新输入").ShowDialog();
					this.textBoxYStart.Focus();
					this.textBoxYStart.SelectAll();
					return;
				}
			}
			else if (this.cmbYStyle.SelectedIndex == 1)
			{
				AxisNameManager.GetLargestNumber(this.m_docment);
				if (AxisNameManager.NumberIsAlreadyExisting(this.m_docment, text))
				{
					new DlgMessage("Y向起始轴号已经存在，请重新输入").ShowDialog();
					this.textBoxYStart.Focus();
					this.textBoxYStart.SelectAll();
				}
			}
		}

		private void gridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
		{
			if (this.gridView.CurrentCell.ColumnIndex == 0 || this.gridView.CurrentCell.ColumnIndex == 1)
			{
				this.EditingControl = (DataGridViewTextBoxEditingControl)e.Control;
				this.EditingControl.KeyPress += this.EditingControl_KeyPress;
				this.EditingControl.TextChanged += this.EditingControl_TextChanged;
			}
		}

		private void gridView_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
		{
			if (e.ColumnIndex == 0 || e.ColumnIndex == 1)
			{
				System.Windows.Forms.TextBox textBox = new System.Windows.Forms.TextBox();
				if (this.gridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)
				{
					textBox.Text = "";
				}
				else
				{
					textBox.Text = this.gridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
				}
				this.NotePastText(textBox, ref this.PastText);
			}
		}

		private void gridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
		{
			this.EditingControl.KeyPress -= this.EditingControl_KeyPress;
			this.EditingControl.TextChanged -= this.EditingControl_TextChanged;
			this.RefreshControls();
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void EditingControl_TextChanged(object sender, EventArgs e)
		{
			if (this.IsNumeric(this.EditingControl.Text, true, false))
			{
				this.NotePastText(this.EditingControl, ref this.PastText);
				return;
			}
			this.RestoreText(this.EditingControl, this.PastText);
		}

		private void EditingControl_KeyPress(object sender, KeyPressEventArgs e)
		{
			this.CheckKeyIn(e, false);
		}

		private bool IsNumeric(string NumStr, bool MayEmpty, bool ContainDot)
		{
			if ((NumStr ?? "") == "")
			{
				return MayEmpty;
			}
			if (ContainDot)
			{
				int num = NumStr.IndexOf('.');
				if (num >= 0)
				{
					num = NumStr.IndexOf('.', num + 1);
					if (num >= 0)
					{
						return false;
					}
				}
			}
			else if (NumStr.IndexOf('.') >= 0)
			{
				return false;
			}
			char[] array = NumStr.ToCharArray();
			for (int i = 0; i <= array.GetUpperBound(0); i++)
			{
				if (!char.IsDigit(array[i]))
				{
					if (array[i] != '.')
					{
						return false;
					}
					if (!ContainDot)
					{
						return false;
					}
				}
			}
			return !ContainDot || NumStr.Replace('.', '\0').Length > 0;
		}

		private void CheckKeyIn(KeyPressEventArgs Key, bool AllowDot)
		{
			if (char.IsControl(Key.KeyChar))
			{
				return;
			}
			if (char.IsDigit(Key.KeyChar))
			{
				return;
			}
			if (Key.KeyChar == '.')
			{
				if (!AllowDot)
				{
					Key.KeyChar = '\0';
				}
				return;
			}
			Key.KeyChar = '\0';
		}

		private void NotePastText(DataGridViewTextBoxEditingControl txtFrom, ref RectAxisForm.struPastText NoteTo)
		{
			if (txtFrom.Text == "" || txtFrom.Text == null)
			{
				txtFrom.Text = "0";
			}
			NoteTo.Text = txtFrom.Text;
			NoteTo.SelStart = txtFrom.SelectionStart;
			NoteTo.SelLength = txtFrom.SelectionLength;
		}

		private void NotePastText(System.Windows.Forms.TextBox txtFrom, ref RectAxisForm.struPastText NoteTo)
		{
			if (txtFrom.Text == "" || txtFrom.Text == null)
			{
				txtFrom.Text = "0";
			}
			NoteTo.Text = txtFrom.Text;
			NoteTo.SelStart = txtFrom.SelectionStart;
			NoteTo.SelLength = txtFrom.SelectionLength;
		}

		private void RestoreText(DataGridViewTextBoxEditingControl txtRestoreTo, RectAxisForm.struPastText TextFrom)
		{
			txtRestoreTo.Text = TextFrom.Text;
			txtRestoreTo.SelectionStart = TextFrom.SelStart;
			txtRestoreTo.SelectionLength = TextFrom.SelLength;
		}

		private void RefreshPreview(Graphics g)
		{
			if (this.IsChange)
			{
				this.IsChange = false;
				List<CurveInfo> list = new List<CurveInfo>();
				RectAxisCreator rectAxisCreator = new RectAxisCreator(this.revit, this.revit.Application, this.m_dataFromDlg);
				CurveArray curveArray = rectAxisCreator.CreateXAxisCurvesWithoutExtend(XYZ.Zero);
				CurveArray curveArray2 = rectAxisCreator.CreateYAxisCurvesWithoutExtend(XYZ.Zero);
				CurveArray dimCurve = rectAxisCreator.GetDimCurve(curveArray);
				CurveArray dimCurve2 = rectAxisCreator.GetDimCurve(curveArray2);
				Transform.CreateRotationAtPoint(XYZ.BasisZ, AssistFunc.AngleToRadian(this.m_dataFromDlg.Angle), XYZ.Zero);
				foreach (object obj in curveArray)
				{
					Curve curve = (Curve)obj;
					CurveInfo item = new CurveInfo(curve, PenColor.PC_Blue, 1f);
					list.Add(item);
					if (this.cbxDown.Checked)
					{
						if (this.m_dataFromDlg.ExtendX == 0.0)
						{
							XYZ center = curve.GetEndPoint(0) - (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize() * 1.5;
							Arc curve2 = this.m_docment.CreatYJKArc(center, 1.5, 0.0, 6.2731853071795864, XYZ.BasisX, XYZ.BasisY);
							CurveInfo item2 = new CurveInfo(curve2, PenColor.PC_Blue, 1f);
							list.Add(item2);
						}
						else
						{
							Line curve3 = YJKLineEx.YJKGetBound(curve.GetEndPoint(0), curve.GetEndPoint(0) - (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendX));
							Line curve4 = YJKLineEx.YJKGetBound(curve.GetEndPoint(1), curve.GetEndPoint(1) + (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendX));
							XYZ center2 = curve3.GetEndPoint(1) + (curve3.GetEndPoint(1) - curve3.GetEndPoint(0)).Normalize() * 1.5;
							Arc curve5 = this.m_docment.CreatYJKArc(center2, 1.5, 0.0, 6.2731853071795864, XYZ.BasisX, XYZ.BasisY);
							CurveInfo item3 = new CurveInfo(curve5, PenColor.PC_Blue, 1f);
							CurveInfo item4 = new CurveInfo(curve3, PenColor.PC_Blue, 1f);
							CurveInfo item5 = new CurveInfo(curve4, PenColor.PC_Blue, 1f);
							list.Add(item4);
							list.Add(item5);
							list.Add(item3);
						}
					}
					if (this.cbxUp.Checked)
					{
						if (this.m_dataFromDlg.ExtendX == 0.0)
						{
							XYZ center3 = curve.GetEndPoint(1) + (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize() * 1.5;
							Arc curve6 = this.m_docment.CreatYJKArc(center3, 1.5, 0.0, 6.2731853071795864, XYZ.BasisX, XYZ.BasisY);
							CurveInfo item6 = new CurveInfo(curve6, PenColor.PC_Blue, 1f);
							list.Add(item6);
						}
						else
						{
							Line curve7 = YJKLineEx.YJKGetBound(curve.GetEndPoint(0), curve.GetEndPoint(0) - (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendX));
							Line curve8 = YJKLineEx.YJKGetBound(curve.GetEndPoint(1), curve.GetEndPoint(1) + (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendX));
							XYZ center4 = curve8.GetEndPoint(1) + (curve8.GetEndPoint(1) - curve8.GetEndPoint(0)).Normalize() * 1.5;
							Arc curve9 = this.m_docment.CreatYJKArc(center4, 1.5, 0.0, 6.2731853071795864, XYZ.BasisX, XYZ.BasisY);
							CurveInfo item7 = new CurveInfo(curve9, PenColor.PC_Blue, 1f);
							CurveInfo item8 = new CurveInfo(curve7, PenColor.PC_Blue, 1f);
							CurveInfo item9 = new CurveInfo(curve8, PenColor.PC_Blue, 1f);
							list.Add(item8);
							list.Add(item9);
							list.Add(item7);
						}
					}
					if (!this.cbxUp.Checked && !this.cbxDown.Checked && this.m_dataFromDlg.ExtendX != 0.0)
					{
						Line curve10 = YJKLineEx.YJKGetBound(curve.GetEndPoint(1), curve.GetEndPoint(1) + (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendX));
						Line curve11 = YJKLineEx.YJKGetBound(curve.GetEndPoint(0), curve.GetEndPoint(0) - (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendX));
						CurveInfo item10 = new CurveInfo(curve10, PenColor.PC_Blue, 1f);
						CurveInfo item11 = new CurveInfo(curve11, PenColor.PC_Blue, 1f);
						list.Add(item10);
						list.Add(item11);
					}
				}
				foreach (object obj2 in curveArray2)
				{
					Curve curve12 = (Curve)obj2;
					CurveInfo item12 = new CurveInfo(curve12, PenColor.PC_Red, 1f);
					list.Add(item12);
					if (this.cbxRight.Checked)
					{
						if (this.m_dataFromDlg.ExtendY == 0.0)
						{
							XYZ center5 = curve12.GetEndPoint(0) + (curve12.GetEndPoint(0) - curve12.GetEndPoint(1)).Normalize() * 1.5;
							Arc curve13 = this.m_docment.CreatYJKArc(center5, 1.5, 0.0, 6.2731853071795864, XYZ.BasisX, XYZ.BasisY);
							CurveInfo item13 = new CurveInfo(curve13, PenColor.PC_Red, 1f);
							list.Add(item13);
						}
						else
						{
							Line curve14 = YJKLineEx.YJKGetBound(curve12.GetEndPoint(0), curve12.GetEndPoint(0) - (curve12.GetEndPoint(1) - curve12.GetEndPoint(0)).Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendY));
							Line curve15 = YJKLineEx.YJKGetBound(curve12.GetEndPoint(1), curve12.GetEndPoint(1) + (curve12.GetEndPoint(1) - curve12.GetEndPoint(0)).Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendY));
							XYZ center6 = curve14.GetEndPoint(1) + (curve14.GetEndPoint(1) - curve14.GetEndPoint(0)).Normalize() * 1.5;
							Arc curve16 = this.m_docment.CreatYJKArc(center6, 1.5, 0.0, 6.2731853071795864, XYZ.BasisX, XYZ.BasisY);
							CurveInfo item14 = new CurveInfo(curve16, PenColor.PC_Red, 1f);
							CurveInfo item15 = new CurveInfo(curve14, PenColor.PC_Red, 1f);
							CurveInfo item16 = new CurveInfo(curve15, PenColor.PC_Red, 1f);
							list.Add(item15);
							list.Add(item16);
							list.Add(item14);
						}
					}
					if (this.cbxLeft.Checked)
					{
						if (this.m_dataFromDlg.ExtendY == 0.0)
						{
							XYZ center7 = curve12.GetEndPoint(1) - (curve12.GetEndPoint(0) - curve12.GetEndPoint(1)).Normalize() * 1.5;
							Arc curve17 = this.m_docment.CreatYJKArc(center7, 1.5, 0.0, 6.2731853071795864, XYZ.BasisX, XYZ.BasisY);
							CurveInfo item17 = new CurveInfo(curve17, PenColor.PC_Red, 1f);
							list.Add(item17);
						}
						else
						{
							Line curve18 = YJKLineEx.YJKGetBound(curve12.GetEndPoint(0), curve12.GetEndPoint(0) - (curve12.GetEndPoint(1) - curve12.GetEndPoint(0)).Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendY));
							Line curve19 = YJKLineEx.YJKGetBound(curve12.GetEndPoint(1), curve12.GetEndPoint(1) + (curve12.GetEndPoint(1) - curve12.GetEndPoint(0)).Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendY));
							XYZ center8 = curve19.GetEndPoint(1) - (curve19.GetEndPoint(0) - curve19.GetEndPoint(1)).Normalize() * 1.5;
							Arc curve20 = this.m_docment.CreatYJKArc(center8, 1.5, 0.0, 6.2731853071795864, XYZ.BasisX, XYZ.BasisY);
							CurveInfo item18 = new CurveInfo(curve20, PenColor.PC_Red, 1f);
							CurveInfo item19 = new CurveInfo(curve18, PenColor.PC_Red, 1f);
							CurveInfo item20 = new CurveInfo(curve19, PenColor.PC_Red, 1f);
							list.Add(item19);
							list.Add(item20);
							list.Add(item18);
						}
					}
					if (!this.cbxRight.Checked && !this.cbxLeft.Checked && this.m_dataFromDlg.ExtendY != 0.0)
					{
						Line curve21 = YJKLineEx.YJKGetBound(curve12.GetEndPoint(1), curve12.GetEndPoint(1) + (curve12.GetEndPoint(1) - curve12.GetEndPoint(0)).Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendY));
						Line curve22 = YJKLineEx.YJKGetBound(curve12.GetEndPoint(0), curve12.GetEndPoint(0) - (curve12.GetEndPoint(1) - curve12.GetEndPoint(0)).Normalize() * AssistFunc.mmToFeet(this.m_dataFromDlg.ExtendY));
						CurveInfo item21 = new CurveInfo(curve21, PenColor.PC_Red, 1f);
						CurveInfo item22 = new CurveInfo(curve22, PenColor.PC_Red, 1f);
						list.Add(item21);
						list.Add(item22);
					}
				}
				if (this.checkBoxDim.Checked)
				{
					foreach (object obj3 in dimCurve)
					{
						Curve curve23 = (Curve)obj3;
						CurveInfo item23 = new CurveInfo(curve23, PenColor.PC_Green, 2f);
						list.Add(item23);
					}
					foreach (object obj4 in dimCurve2)
					{
						Curve curve24 = (Curve)obj4;
						CurveInfo item24 = new CurveInfo(curve24, PenColor.PC_Green, 2f);
						list.Add(item24);
					}
				}
				this.pictureBox3.Curves = list;
				this.pictureBox3.ZoomExtents();
			}
		}

		private void gridView_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
		{
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void gridView_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
		{
			this.RefreshControls();
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void RectAxisForm_Load(object sender, EventArgs e)
		{
			this.ShowHideMoreParam();
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void cbxLeft_CheckedChanged(object sender, EventArgs e)
		{
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void gridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
		{
			int rowIndex = e.RowIndex;
			if (rowIndex == this.gridView.RowCount - 1)
			{
				DataGridViewCell dataGridViewCell = this.gridView.Rows[rowIndex].Cells[0];
				if (dataGridViewCell.Value != null && dataGridViewCell.Value.ToString().CompareTo("0") == 0)
				{
					double dist = Convert.ToDouble(0);
					if (this.radioLeft.Checked)
					{
						this.AddRow1(this.m_dataFromDlg.LeftData, this.bindingSourceLeft, dist);
					}
					else if (this.radioRight.Checked)
					{
						this.AddRow1(this.m_dataFromDlg.RightData, this.bindingSourceRight, dist);
					}
					else if (this.radioUp.Checked)
					{
						this.AddRow1(this.m_dataFromDlg.TopData, this.bindingSourceTop, dist);
					}
					else if (this.radioDown.Checked)
					{
						this.AddRow1(this.m_dataFromDlg.DownData, this.bindingSourceDown, dist);
					}
					this.RefreshControls();
					this.IsChange = true;
					this.pictureBox3.Refresh();
					return;
				}
			}
			else if (rowIndex != -1)
			{
				if (this.radioLeft.Checked)
				{
					this.FilterNullRow(this.m_dataFromDlg.LeftData);
				}
				else if (this.radioRight.Checked)
				{
					this.FilterNullRow(this.m_dataFromDlg.RightData);
				}
				else if (this.radioUp.Checked)
				{
					this.FilterNullRow(this.m_dataFromDlg.TopData);
				}
				else
				{
					this.FilterNullRow(this.m_dataFromDlg.DownData);
				}
				this.gridView.Refresh();
			}
		}

		private void FilterNullRow(List<AxisListItem> data)
		{
			if (data.Count < 1)
			{
				return;
			}
			if (data.Count != this.gridView.RowCount)
			{
				return;
			}
			AxisListItem axisListItem = data[data.Count - 1];
			if (axisListItem.Number == 0 || object.Equals(axisListItem.Dist, 0.0))
			{
				data.RemoveAt(data.Count - 1);
			}
		}

		private void FilterNullRow()
		{
			if (this.m_PreviousDataSourceType == RectAxisForm.DataSourceType.DST_NONE)
			{
				return;
			}
			if (this.m_PreviousDataSourceType == RectAxisForm.DataSourceType.DST_LEFT)
			{
				this.FilterNullRow(this.m_dataFromDlg.LeftData);
				return;
			}
			if (this.m_PreviousDataSourceType == RectAxisForm.DataSourceType.DST_RIGHT)
			{
				this.FilterNullRow(this.m_dataFromDlg.RightData);
				return;
			}
			if (this.m_PreviousDataSourceType == RectAxisForm.DataSourceType.DST_UP)
			{
				this.FilterNullRow(this.m_dataFromDlg.TopData);
				return;
			}
			this.FilterNullRow(this.m_dataFromDlg.DownData);
		}

		private void pictureBox3_Paint(object sender, PaintEventArgs e)
		{
			Graphics graphics = e.Graphics;
			graphics.Clear(System.Drawing.Color.Black);
			this.RefreshPreview(graphics);
		}

		private void cbxRight_CheckedChanged(object sender, EventArgs e)
		{
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void cbxUp_CheckedChanged(object sender, EventArgs e)
		{
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void cbxDown_CheckedChanged(object sender, EventArgs e)
		{
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void textBoxXStart_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (this.cmbXStyle.Text.Substring(0, 1) == "1")
			{
				if (!char.IsNumber(e.KeyChar) && e.KeyChar != '\r' && e.KeyChar != '\b')
				{
					e.Handled = true;
					return;
				}
			}
			else if (!char.IsLetter(e.KeyChar) && e.KeyChar != '\r' && e.KeyChar != '\b')
			{
				e.Handled = true;
			}
		}

		private void textBoxYStart_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (this.cmbXStyle.Text.Substring(0, 1) == "1")
			{
				if (!char.IsLetter(e.KeyChar) && e.KeyChar != '\r' && e.KeyChar != '\b')
				{
					e.Handled = true;
					return;
				}
			}
			else if (!char.IsNumber(e.KeyChar) && e.KeyChar != '\r' && e.KeyChar != '\b')
			{
				e.Handled = true;
			}
		}

		private void RectAxisForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (((System.Windows.Forms.Form)sender).DialogResult == DialogResult.OK)
			{
				if (!this.DataIsCorrect())
				{
					e.Cancel = true;
					return;
				}
				this.m_dataFromDlg.Angle = ((this.textBoxAngle.Text == "") ? 0.0 : Convert.ToDouble(this.textBoxAngle.Text));
				this.m_dataFromDlg.GridType = this.cmbGridType.SelectedItem.ToString();
				this.m_dataFromDlg.WithDim = this.checkBoxDim.Checked;
				this.m_dataFromDlg.DimType = (this.cmbDimType.SelectedItem as ShowDimensionType).Type;
				this.m_dataFromDlg.XStyle = this.cmbXStyle.SelectedIndex;
				this.m_dataFromDlg.XStart = this.textBoxXStart.Text;
				this.m_dataFromDlg.XReverse = this.checkBoxXRev.Checked;
				this.m_dataFromDlg.YStyle = this.cmbXStyle.SelectedIndex;
				this.m_dataFromDlg.YStart = this.textBoxYStart.Text;
				this.m_dataFromDlg.YReverse = this.checkBoxYRev.Checked;
				this.m_dataFromDlg.Up = this.cbxUp.Checked;
				this.m_dataFromDlg.Down = this.cbxDown.Checked;
				this.m_dataFromDlg.Left = this.cbxLeft.Checked;
				this.m_dataFromDlg.Right = this.cbxRight.Checked;
				this.m_dataFromDlg.ExtendX = ((this.extendA.Text == "") ? 0.0 : Convert.ToDouble(this.extendA.Text));
				this.m_dataFromDlg.ExtendY = ((this.extendB.Text == "") ? 0.0 : Convert.ToDouble(this.extendB.Text));
				this.SaveAxisData();
			}
		}

		private void gridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
		{
			if (e.Button == MouseButtons.Right && e.RowIndex >= 0 && e.RowIndex < this.gridView.Rows.Count - 1)
			{
				if (!this.gridView.Rows[e.RowIndex].Selected)
				{
					this.gridView.ClearSelection();
					this.gridView.Rows[e.RowIndex].Selected = true;
				}
				if (this.gridView.SelectedRows.Count == 1 && e.ColumnIndex >= 0)
				{
					this.gridView.CurrentCell = this.gridView.Rows[e.RowIndex].Cells[e.ColumnIndex];
				}
				this.cmsGirdView.Show(System.Windows.Forms.Control.MousePosition.X, System.Windows.Forms.Control.MousePosition.Y);
			}
		}

		private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.gridView.Rows.Remove(this.gridView.SelectedRows[0]);
		}

		private void 插入ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			double dist = 0.0;
			if (this.listDist.SelectedItem != null)
			{
				dist = Convert.ToDouble(this.listDist.SelectedItem);
			}
			if (this.radioLeft.Checked)
			{
				this.bindingSourceLeft.Insert(this.gridView.CurrentRow.Index + 1, new AxisListItem(1, dist));
				return;
			}
			if (this.radioRight.Checked)
			{
				this.bindingSourceRight.Insert(this.gridView.CurrentRow.Index + 1, new AxisListItem(1, dist));
				return;
			}
			if (this.radioUp.Checked)
			{
				this.bindingSourceTop.Insert(this.gridView.CurrentRow.Index + 1, new AxisListItem(1, dist));
				return;
			}
			if (this.radioDown.Checked)
			{
				this.bindingSourceDown.Insert(this.gridView.CurrentRow.Index + 1, new AxisListItem(1, dist));
			}
		}

		private void 上移toolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.gridView.CurrentRow == null || this.gridView.CurrentRow.IsNewRow)
			{
				return;
			}
			if (this.gridView.CurrentRow.Index <= 0)
			{
				return;
			}
			this.MovePrevious();
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void MovePrevious()
		{
			if (this.gridView.SelectedRows.Count > 0)
			{
				if (this.gridView.SelectedRows[0].IsNewRow)
				{
					return;
				}
				int index = this.gridView.CurrentRow.Index;
				int number = Convert.ToInt32(this.gridView.Rows[index].Cells[0].Value.ToString());
				double dist = Convert.ToDouble(this.gridView.Rows[index].Cells[1].Value.ToString());
				this.gridView.Rows.RemoveAt(index);
				if (this.radioLeft.Checked)
				{
					this.bindingSourceLeft.Insert(index - 1, new AxisListItem(number, dist));
				}
				else if (this.radioRight.Checked)
				{
					this.bindingSourceRight.Insert(index - 1, new AxisListItem(number, dist));
				}
				else if (this.radioUp.Checked)
				{
					this.bindingSourceTop.Insert(index - 1, new AxisListItem(number, dist));
				}
				else if (this.radioDown.Checked)
				{
					this.bindingSourceDown.Insert(index - 1, new AxisListItem(number, dist));
				}
				this.gridView.Rows[index - 1].Selected = true;
				this.gridView.CurrentCell = this.gridView.Rows[index - 1].Cells[0];
				this.IsChange = true;
				this.pictureBox3.Refresh();
			}
		}

		private void 下移toolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.gridView.CurrentRow == null || this.gridView.CurrentRow.IsNewRow)
			{
				return;
			}
			if (this.gridView.CurrentRow.Index >= this.gridView.RowCount - 2)
			{
				return;
			}
			this.MoveNext();
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void MoveNext()
		{
			if (this.gridView.SelectedRows.Count > 0)
			{
				if (this.gridView.SelectedRows[0].IsNewRow)
				{
					return;
				}
				int index = this.gridView.CurrentRow.Index;
				int number = Convert.ToInt32(this.gridView.Rows[index].Cells[0].Value.ToString());
				double dist = Convert.ToDouble(this.gridView.Rows[index].Cells[1].Value.ToString());
				this.gridView.Rows.RemoveAt(index);
				if (this.radioLeft.Checked)
				{
					this.bindingSourceLeft.Insert(index + 1, new AxisListItem(number, dist));
				}
				else if (this.radioRight.Checked)
				{
					this.bindingSourceRight.Insert(index + 1, new AxisListItem(number, dist));
				}
				else if (this.radioUp.Checked)
				{
					this.bindingSourceTop.Insert(index + 1, new AxisListItem(number, dist));
				}
				else if (this.radioDown.Checked)
				{
					this.bindingSourceDown.Insert(index + 1, new AxisListItem(number, dist));
				}
				this.gridView.Rows[index + 1].Selected = true;
				this.gridView.CurrentCell = this.gridView.Rows[index + 1].Cells[0];
				this.IsChange = true;
				this.pictureBox3.Refresh();
			}
		}

		private void textBoxAngle_TextChanged(object sender, EventArgs e)
		{
			if (!Common.IsValidating(this.textBoxAngle.Text, 0.0, 360.0))
			{
				MessageBox.Show("请输入0～360之间的整数");
				this.textBoxAngle.Text = this.m_dataFromDlg.Angle.ToString("f0");
				return;
			}
			this.m_dataFromDlg.Angle = Convert.ToDouble(this.textBoxAngle.Text);
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void extendB_TextChanged(object sender, EventArgs e)
		{
			if (!Common.IsValidating(this.extendB.Text, 0.0, 10000.0))
			{
				MessageBox.Show("请输入0～10000之间的整数");
				this.extendB.Text = this.m_dataFromDlg.ExtendY.ToString("f0");
				return;
			}
			this.m_dataFromDlg.ExtendY = Convert.ToDouble(this.extendB.Text);
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void extendA_TextChanged(object sender, EventArgs e)
		{
			if (!Common.IsValidating(this.extendA.Text, 0.0, 10000.0))
			{
				MessageBox.Show("请输入0～10000之间的整数");
				this.extendA.Text = this.m_dataFromDlg.ExtendX.ToString("f0");
				return;
			}
			this.m_dataFromDlg.ExtendX = Convert.ToDouble(this.extendA.Text);
			this.IsChange = true;
			this.pictureBox3.Refresh();
		}

		private void textBoxAngle_Leave(object sender, EventArgs e)
		{
			if (this.textBoxAngle.Text != "")
			{
				this.m_dataFromDlg.Angle = Convert.ToDouble(this.textBoxAngle.Text);
				return;
			}
			this.textBoxAngle.Text = "0";
			this.m_dataFromDlg.Angle = Convert.ToDouble(this.textBoxAngle.Text);
		}

		private void extendA_Leave(object sender, EventArgs e)
		{
			if (this.extendA.Text != "")
			{
				this.m_dataFromDlg.ExtendX = Convert.ToDouble(this.extendA.Text);
				return;
			}
			this.extendA.Text = "3000";
			this.m_dataFromDlg.ExtendX = Convert.ToDouble(this.extendA.Text);
		}

		private void extendB_Leave(object sender, EventArgs e)
		{
			if (this.extendB.Text != "")
			{
				this.m_dataFromDlg.ExtendY = Convert.ToDouble(this.extendB.Text);
				return;
			}
			this.extendB.Text = "3000";
			this.m_dataFromDlg.ExtendY = Convert.ToDouble(this.extendB.Text);
		}

		public RectAxisDataFromDlg m_dataFromDlg;

		private Document m_docment;

		private ExternalCommandData revit;

		private bool m_bExpand;

		private RectAxisForm.DataSourceType m_PreviousDataSourceType;

		private DataGridViewTextBoxEditingControl EditingControl = new DataGridViewTextBoxEditingControl();

		private RectAxisForm.struPastText PastText;

		private bool IsChange;

		private DataGridViewTextBoxColumn Number;

		private DataGridViewTextBoxColumn Dist;

		private Previewer pictureBox3;

		private enum DataSourceType
		{
			DST_NONE,
			DST_LEFT,
			DST_RIGHT,
			DST_UP,
			DST_DOWN
		}

		private struct struPastText
		{
			public struPastText(string txt, int Start, int Length)
			{
				this.Text = txt;
				this.SelStart = Start;
				this.SelLength = Length;
			}

			public string Text;

			public int SelStart;

			public int SelLength;
		}
	}
}
